package space

import (
	"src/zeus/iserver"
	"src/zeus/msgdef"

	"src/zeus/logger"
)

type SpaceSessesMsgProc struct {
	srv *SpaceSesses
}

// 连接到我的客户端 已经验证通过
func (proc *SpaceSessesMsgProc) MsgProc_SessVerified(content interface{}) {
	im := content.(msgdef.ISessionVerifyReqMsg)
	uid := im.GetSessVerifyPID()

	sess := proc.srv.clientSrv.GetSession(uid)
	if sess == nil {
		logger.Error("couldn't found sess ", uid)
		return
	}

	// Source 为1 代表是 SpaceSess
	sess.Send(&msgdef.ClientVerifySucceedRet{
		Source:   1,
		PID:      uid,
		SourceID: iserver.GetSrvInst().GetSrvID(),
		Type:     0,
	})

	logger.Debug(logger.LogKey_Default, "space sess establish !! ", content)
}

func (proc *SpaceSessesMsgProc) MsgProc_SpaceUserConnect(msg *msgdef.SpaceUserConnect) {
	sess := proc.srv.clientSrv.GetSession(msg.UID)
	if sess == nil {
		logger.Error("space user connected but not find sess ", msg.UID)
		return
	}

	space := iserver.GetSrvInst().GetEntity(msg.SpaceID)
	if space == nil {
		logger.Error("couldn't find space ", msg.SpaceID)
		return
	}

	imh, ok := space.(iserver.IMsgHandler)
	if !ok {
		logger.Error("this not go happen")
		return
	}

	imh.FireMsg("SpaceUserSess", sess)
}
